<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/6
 * Time: 11:38
 */
namespace app\api\controller;
use think\App;
/*
 * 买卖单处理类
 */
class Order extends BaseController
{
    protected $orderModel;
    public function __construct(App $app = null)
    {
        parent::__construct($app);
        $this->orderModel = new \app\api\model\Order();
    }

    /**
     * 矿工挂卖
     */
    public function saleOrder()
    {
        $result = $this->orderModel->saleOrder($this->uid);
        AjaxReturn($result['code'],$result['msg']);
    }

    /**
     * 矿工挂买
     */
    public function buyOrder()
    {
        $result = $this->orderModel->buyOrder($this->uid);
        AjaxReturn($result['code'],$result['msg']);
    }

    /**
     * 查看订单详情
     *
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function orderInfo()
    {
        $result = $this->orderModel->orderInfo($this->uid);
        AjaxReturn($result['code'],$result['msg'],$result['data']);
    }

    /**
     * 查看订单列表
     *
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getOrderList()
    {
        $result = $this->orderModel->getOrderList($this->uid);
        AjaxReturn($result['code'],$result['msg'],$result['data']);
    }

    /**
     * 购买矿工(卖单购买)
     */
    public function purchase()
    {
        $result = $this->orderModel->purchase($this->uid);
        AjaxReturn($result['code'],$result['msg'],$result['data']);
    }

    /**
     * 出售矿工(买单出售)
     */
    public function sell()
    {
        $result = $this->orderModel->sell($this->uid);
        AjaxReturn($result['code'],$result['msg'],$result['data']);
    }

    /**
     * 卖单撤回
     */
    public function saleOrderCancle()
    {
        $result = $this->orderModel->saleOrderCancle($this->uid);
        AjaxReturn($result['code'],$result['msg'],$result['data']);
    }

    /**
     * 挂买单撤回
     *
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function buyOrderCancle()
    {
        $result = $this->orderModel->buyOrderCancle($this->uid);
        AjaxReturn($result['code'],$result['msg'],$result['data']);
    }

    /**
     * 我的订单
     */
    public function myOrders()
    {
        $result = $this->orderModel->myOrder($this->uid);
        AjaxReturn($result['code'],$result['msg'],$result['data']);
    }
}